//
//  VRNetWorkTool.swift
//  Sina_MicoBlog
//
//  Created by Lee on 16/5/13.
//  Copyright © 2016年 Lee.C. All rights reserved.
//
//第三方框架是需要导入头文件的,
//这里创建一个单例,但是这个类不能继承第三方afn,不让别人调用这个类来进行网络请求.
//我们在创立完单例后,搞一个AFN类型的属性就可以了,到时用.就可以用到,我们有闭包式创建这个属性,并设置他的值,就像懒加载的方法,但是不是懒加载.
//创建枚举,封装get和post请求方法.
//创建单例和封装完方法以后,回到Oauth控制器.只是为Oauth
import UIKit
import AFNetworking

enum RequestMethod: String{

    case GET = "GET"
    case POST = "POST"

}

class VRNetWorkTool: NSObject {

    static let shareInstance: VRNetWorkTool = VRNetWorkTool()
  private  let afnManager: AFHTTPSessionManager = {
    let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
    afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return afn
    }()
    
    func request(method: RequestMethod,URLString: String,parameters: AnyObject?,success: ((NSURLSessionDataTask, AnyObject?) -> Void)?,failure:((NSURLSessionDataTask?, NSError) -> Void)?) {
        if method == RequestMethod.GET{
            afnManager.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
        if method == RequestMethod.POST{
        afnManager.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
    
    }
}
